package com.algrithom.stack;

import java.util.Scanner;

/**
 * 括号的分数
 *
 * @author think
 * @version 1.0.0
 * @since 2019/12/31
 */
public class Solution1 {
    
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        System.out.println(scoreOfParentheses(str));
    }
    
    private static int scoreOfParentheses(String str){
        return cals(str,0,str.length());
    }
    
    private static int cals(String str,int start,int end){
        int ans = 0;
        int bal = 0;
        
        for (int k = start; k < end; ++k) {
            bal += str.charAt(k) == '(' ? 1 : -1;
            if (bal == 0) {
                if (k - start == 1) {
                    ans++;
                } else {
                    ans += 2 * cals(str,start + 1,k);
                }
                start = k + 1;
            }
        }
        
        return ans;
    }
}
